﻿
using System.Collections.Generic;
using System.Data;
using System;
namespace ZHDJ.MobileInterface
{
    public partial class GetPartyForumDital : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            PartyForumDitalOutParam result = new PartyForumDitalOutParam();
            PartyForumDitalInParam param = new PartyForumDitalInParam();
            string logMsg = "";
            bool isFlag = true;
                 
            try
            {
                param = inParam as PartyForumDitalInParam;
                if (string.IsNullOrEmpty(param.forum_id))
                {
                    result.code = "0";
                    result.desc = "帖子ID不能为空";

                    isFlag = false;
                } 

                if (isFlag)
                {
                    //帖子是否存在
                    isFlag = InterfaceHelper.PartyForumIsExists(param.forum_id);
                    if (!isFlag)
                    {
                        result.code = "0";
                        result.desc = "该帖子不存在！"; 
                    }
                }
                 
                if(isFlag)
                {

                    int rowCount = InterfaceHelper.GetForumReplyCount(param.forum_id);

                    result.data.total_pages = CommonUtils.GetTotalPages(rowCount, 10);
                    if (result.data.total_pages <= 0)
                        result.data.total_pages = 1;
                    result.data.content_url = CommonUtils.AppAddressEx + "html/PartyForumDital.aspx?ForumID=" + param.forum_id + "&page=" + param.page_no.ToString();
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-PartyForumDital", SerializeHelper.JsonSerializer<PartyForumDitalInParam>(param), logMsg); 
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<PartyForumDitalInParam, PartyForumDitalOutParam>();
            else
                SafeProcessRequest<PartyForumDitalInParam, PartyForumDitalOutParam>();
        }
    }

    #region 请求参数
    public class PartyForumDitalInParam
    {
        /// <summary>
        ///	帖子ID	必须
        /// </summary>
        public string forum_id
        { get; set; }

        /// <summary>
        ///	当前页	必须
        /// </summary>
        public int page_no
        { get; set; }  
    }
    #endregion

    #region 结果参数
    public class PartyForumDitalOutParam
    {
        public PartyForumDitalOutParam()
        {
            code = "1";
            desc = "操作成功";

            data = new PartyForumDitalOutData();
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }

        public PartyForumDitalOutData data
        { get; set; }
    }

    public class PartyForumDitalOutData
    {
        /// <summary>
        /// 帖子详情ＨＴＭＬ页面地址
        /// </summary>
        public string content_url
        { get; set; }

        /// <summary>
        ///	总页数
        /// </summary>
        public int total_pages
        { get; set; }
    }
    #endregion 
}